(in-package "MUDRA")







;;;; The Attributes

(def-dojo-attribute :dojo-type ())

(def-dojo-attribute :content-node-class ())

(def-dojo-attribute :label-node-class ())

(def-dojo-attribute :id ())

(def-dojo-attribute :toggle-duration ())

(def-dojo-attribute :toggle ())

(def-dojo-attribute :title ())

(def-dojo-attribute :label ())

(def-dojo-attribute :widget-id  ())

(def-dojo-attribute :event-names ())

(def-dojo-attribute :selected-tab ())

(def-dojo-attribute :orientation ())  ;; vertical horizontal

(def-dojo-attribute :sizer-width ())

(def-dojo-attribute :style ())

(def-dojo-attribute :size-share ())

(def-dojo-attribute :open ())

(def-dojo-attribute :object ())

(def-dojo-attribute :menu-id ())

(def-dojo-attribute :layout-child-priority ())

(def-dojo-attribute :layout-align ()) ;; top bottom left right client

(def-dojo-attribute :caption ())

(def-dojo-attribute :accel-key ())

(def-dojo-attribute :on-click ())

(def-dojo-attribute :container-node-class ())

(def-dojo-attribute :constrain-to-container ())

(def-dojo-attribute :display-maximize-action ())

(def-dojo-attribute :display-close-action ())

(def-dojo-attribute :display-minimize-action ())

(def-dojo-attribute :window-state ())

(def-dojo-attribute :resizable ())

(def-dojo-attribute :has-shadow ())

(def-dojo-attribute :expand-level ())

(def-dojo-attribute :selector ())

(def-dojo-attribute :name ())

(def-dojo-attribute :value ())

(def-dojo-attribute :autocomplete ())

(def-dojo-attribute :action ())

(def-dojo-attribute :method ())







;;;; The Tags

(defvar *dojo-bootstrap-url?* 
;  "http://o.aolcdn.com/iamalpha/.resource/jssdk/dojo-0.3.1/dojo.js"
  nil)

(defvar *dojo-bootstrap-pathname* "/s/dojo-0.3.1-ajax/dojo.js")

(defhtmltag dojo-configuration (attrs body)
  (assert (null body))
  `(js-script
     (defvar dj-config (create ,@attrs))))

(defhtmltag dojo-bootstrap (attrs body)
  (assert (null attrs))
  (assert (null body))
  `((script
     :type "text/javascript"
     :src ,(or 
	    *dojo-bootstrap-url?*
	    *dojo-bootstrap-pathname*))))

(defhtmltag dojo-require (attrs requires)
  (declare (ignore attrs))
  `(js-script
    ,@(loop for r in requires
	    collect `(dojo.require ,r))))

(defhtmltag dojo-debug (attrs body)
  (let ((attributes (sweep-dojo-attributes attrs)))
    `((div :id "dojoDebug" ,@attributes)
      ,@body)))

;;; Layout Widgets
;; Partitioning
;;   dojo-layout-Container
;;   dojo-split-container
;; One child at a time
;;   dojo-tab-container
;;   dojo-accordion-container
;;   dojo-wizard-container
;; Etc.
;;   dojo-content-pane

(def-dojo-tag dojo-layout-container ())

(def-dojo-tag dojo-split-container (:orientation)
  :extra-attributes
     (:label-node-class "label" :content-node-class "content"))

(def-dojo-tag dojo-tab-container (:selected-tab))  ;; children need :label

(def-dojo-tag dojo-accordion-container ())

(def-dojo-tag dojo-wizard-container ())

(def-dojo-tag dojo-content-pane ())


;;; Panes

(def-dojo-tag dojo-doc-pane (:id))

(def-dojo-tag dojo-title-pane (:label)
  :extra-attributes (:label-node-class "label" :content-node-class "content"))

(defhtmltag dojo-table (attrs body)
  (let ((attributes (sweep-dojo-attributes attrs)))
    `((div :dojo-type "tableContainer")
      ((table :dojo-type "SortableTable" ,@attributes)
       ,@body))))

(def-dojo-tag dojo-floating-pane ())


(def-dojo-tag dojo-dialog ())

;;;; Buttons

(defhtmltag dojo-button (attrs body)
  (let ((attributes (sweep-dojo-attributes attrs)))
    `((button :dojo-type "Button" ,@attributes) ,@body)))

(defhtmltag dojo-dropdown-button (attrs body)
  (assert (getf attrs :menu-id))
  (let ((attributes (sweep-dojo-attributes attrs)))
    `((button :dojo-type "dropdownButton" ,@attributes) ,@body)))

(def-dojo-tag dojo-popup-menu2 (:id))

(def-dojo-tag dojo-menu-item2 (:caption :on-click))

(defhtmltag dojo-combobox (attrs body)
  (let ((attributes (sweep-dojo-attributes attrs)))
    `((select :dojo-type "combobox" ,@attributes)
      ,@body)))




;;;; Outline Tables

(def-dojo-tag dojo-tree () 
  :extra-attributes (:toggle-duration 500 :toggle "fade"))

(def-dojo-tag dojo-tree-node (:title))

(def-dojo-tag dojo-tree-selector (:widget-id :event-names))



;;;; Utilities

(defun sexpr->dojo-tree (list-of-sexpr)
  (labels ((recure (list-of-sexpr)
	     (loop for n in list-of-sexpr
		   collect
		   (cond
		     ((listp n)
		      `((dojo-tree-node :title ,(first n))
			,@(recure (rest n))))
		     (t
		      `((dojo-tree-node :title ,n)))))))
    `(dojo-tree
      ,@(recure list-of-sexpr))))
	       
  